package com.autism.day06;

public class ExceptionDemo {
    public static void main(String[] args) {
        int a = getA();
        System.out.println(a);
    }

    public static int getA() {
        int a = 10;
        try {
            return a;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //避免在finally中使用return
            a = 100;
            return a;
        }
    }
}

/**
 * 字符类异常：
 * 1.父类抛出多个异常，子类重写父类方法时，抛出和父类相同异常或者时父类异常的子类，或者不抛出
 * 2.父类方法没有抛出异常，子类重写该方法也不可以抛出异常，只能捕获异常，不能抛出
 */
class Fu {
    public void test01() throws NullPointerException, ClassCastException {
        System.out.println();
    }

    public void test02() throws IndexOutOfBoundsException {
        System.out.println();
    }

    public void test03() throws IndexOutOfBoundsException {
        System.out.println();
    }

    public void test04() {
        System.out.println();
    }
}

class Zi extends Fu {
    public void test01() throws NullPointerException, ClassCastException {
        System.out.println();
    }

    public void test02() throws ArrayIndexOutOfBoundsException {
        System.out.println();
    }

    public void test03() {
        System.out.println();
    }

    public void test04() {
        System.out.println();
//        throw new Exception("wdnmd");
        try {
            throw new Exception("wdnmd");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

        }
    }
}
